package com.myproject.myblogserver.utils;

import org.mindrot.jbcrypt.BCrypt;
import org.springframework.stereotype.Component;

/**
 * <p>
 * BCrypt加密工具类
 * </p>
 *
 * @author jiangweike
 * @since 2025-2-9
 */
@Component
public class BCryptUtil {
    /**
     * 加密密码
     * 
     * @param plainTextPassword
     * @return
     */
    public static String hashPassword(String plainTextPassword) {
        return BCrypt.hashpw(plainTextPassword, BCrypt.gensalt());
    }

    /**
     * 校验密码
     * 
     * @param plainTextPassword
     * @param hashedPassword
     * @return
     */
    public static boolean checkPassword(String plainTextPassword, String hashedPassword) {
        return BCrypt.checkpw(plainTextPassword, hashedPassword);
    }
}